import 'package:flutter/material.dart';

import 'const.dart';

class Register extends StatefulWidget {
  const Register({super.key});

  @override
  State<Register> createState() => _RegisterState();
}

class _RegisterState extends State<Register> {
  final _Controller1 = TextEditingController();
  final _Controller2 = TextEditingController();
  final _Controller3 = TextEditingController();
  final _Controller4 = TextEditingController();
  final _Controller5 = TextEditingController();
  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Column(
        children: [
          Container(
            height: mScreenHeight * 0.06,
            padding: const EdgeInsets.only(left: 10),
            decoration: BoxDecoration(
                // color: Colors.pink[100],
                borderRadius: BorderRadius.circular(10),
                border: Border.all(width: 1, color: Color(0xFFDDEAFB))),
            child: TextField(
              controller: _Controller1,
              decoration: const InputDecoration(
                border: InputBorder.none,
                hintText: '用户名',
              ),
            ),
          ),
          SizedBox(
            height: mScreenHeight * 0.065,
          ),
          Container(
            height: mScreenHeight * 0.06,
            padding: const EdgeInsets.only(left: 10),
            decoration: BoxDecoration(
                // color: Colors.pink[100],
                borderRadius: BorderRadius.circular(10),
                border: Border.all(width: 1, color: Color(0xFFDDEAFB))),
            child: TextField(
              controller: _Controller2,
              decoration: const InputDecoration(
                border: InputBorder.none,
                hintText: '邮箱',
              ),
            ),
          ),
          SizedBox(
            height: mScreenHeight * 0.065,
          ),
          Container(
            height: mScreenHeight * 0.06,
            padding: const EdgeInsets.only(left: 10),
            decoration: BoxDecoration(
                // color: Colors.pink[100],
                borderRadius: BorderRadius.circular(10),
                border: Border.all(width: 1, color: Color(0xFFDDEAFB))),
            child: TextField(
              controller: _Controller3,
              decoration: const InputDecoration(
                border: InputBorder.none,
                hintText: '手机号（仅限中国大陆）',
              ),
            ),
          ),
          SizedBox(
            height: mScreenHeight * 0.065,
          ),
          Container(
            height: mScreenHeight * 0.06,
            padding: const EdgeInsets.only(left: 10),
            decoration: BoxDecoration(
                // color: Colors.pink[100],
                borderRadius: BorderRadius.circular(10),
                border: Border.all(width: 1, color: Color(0xFFDDEAFB))),
            child: TextField(
              controller: _Controller4,
              decoration: const InputDecoration(
                border: InputBorder.none,
                hintText: '密码（不少于6位）',
              ),
            ),
          ),
          SizedBox(
            height: mScreenHeight * 0.065,
          ),
          Container(
            height: mScreenHeight * 0.06,
            padding: const EdgeInsets.only(left: 10),
            decoration: BoxDecoration(
                // color: Colors.pink[100],
                borderRadius: BorderRadius.circular(10),
                border: Border.all(width: 1, color: Color(0xFFDDEAFB))),
            child: TextField(
              controller: _Controller5,
              decoration: const InputDecoration(
                border: InputBorder.none,
                hintText: '再次输入密码',
              ),
            ),
          ),
          SizedBox(
            height: mScreenHeight * 0.065,
          ),
          GestureDetector(
            onTap: () {
              if (_Controller1.text != '' &&
                  _Controller2.text != '' &&
                  _Controller3.text != '' &&
                  _Controller4.text != '' &&
                  _Controller5.text != '') {
                if (_Controller4.text != _Controller5.text) {
                  showDialog(
                      context: context,
                      builder: (BuildContext context) {
                        return AlertDialog(
                          title: const Text('提示'),
                          content: const Text(
                            '两次密码不一致',
                            style: TextStyle(fontSize: 18),
                          ),
                          actions: [
                            TextButton(
                                onPressed: () {
                                  Navigator.of(context).pop();
                                },
                                child: const Text('返回'))
                          ],
                        );
                      });
                  return;
                }
                showDialog(
                    context: context,
                    builder: (BuildContext context) {
                      return AlertDialog(
                        title: const Text('提示'),
                        content: const Text(
                          '注册成功',
                          style: TextStyle(fontSize: 18),
                        ),
                        actions: [
                          TextButton(
                              onPressed: () {
                                name = _Controller1.text;
                                password = _Controller4.text;
                                Navigator.of(context).pop();
                                tabController.animateTo(1);
                              },
                              child: const Text('去登录'))
                        ],
                      );
                    });
              } else {
                showDialog(
                    context: context,
                    builder: (BuildContext context) {
                      return AlertDialog(
                        title: const Text('提示'),
                        content: const Text(
                          '信息输入不全',
                          style: TextStyle(fontSize: 18),
                        ),
                        actions: [
                          TextButton(
                              onPressed: () {
                                Navigator.of(context).pop();
                              },
                              child: const Text('返回'))
                        ],
                      );
                    });
              }
            },
            child: Container(
                width: double.infinity,
                height: mScreenHeight * 0.065,
                decoration: BoxDecoration(
                    color: Color(0xFF2B88EB),
                    borderRadius: BorderRadius.circular(10)),
                child: Center(
                    child: Text(
                  '注册',
                  style: TextStyle(color: Colors.white, fontSize: 18),
                ))),
          ),
        ],
      ),
    );
  }
}
